package com.xtedu.examproject.dao.impl;

import com.xtedu.examproject.dao.base.UploadedFileDao;
import com.xtedu.examproject.entity.UploadedFile;
import com.xtedu.examproject.util.DBUtil;
import com.xtedu.examproject.util.PageHelper;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.List;

/*
 * Author: xzy
 * Date: 2025/10/15
 * Last Modified by: xzy
 * Last Modified date: 2025/10/15
 * Description: TODO - Add file description here
 */
public class UploadedFileDaoImpl implements UploadedFileDao {
    @Override
    public int insert(UploadedFile uploadedFile) throws Exception {
        String sql = "INSERT INTO uploaded_files (original_name, saved_name, file_size, content_type, upload_time, upload_path, exam_id) VALUES (?, ?, ?, ?, ?, ?, ?)";
        try (
                Connection conn = DBUtil.getConnection();
                PreparedStatement pstmt = conn.prepareStatement(sql)
        ) {
            pstmt.setString(1, uploadedFile.getOriginalName());
            pstmt.setString(2, uploadedFile.getSavedName());
            pstmt.setLong(3, uploadedFile.getFileSize());
            pstmt.setString(4, uploadedFile.getContentType());
            pstmt.setTimestamp(5, uploadedFile.getUploadTime());
            pstmt.setString(6, uploadedFile.getUploadPath());
            pstmt.setInt(7, uploadedFile.getExamId());
            return pstmt.executeUpdate();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public int update(UploadedFile uploadedFile) throws Exception {
        return 0;
    }

    @Override
    public int delete(UploadedFile uploadedFile) throws Exception {
        return 0;
    }

    @Override
    public int deleteById(int id) throws Exception {
        return 0;
    }

    @Override
    public UploadedFile findById(int id) throws Exception {
        return null;
    }

    @Override
    public List<UploadedFile> findAll() throws Exception {
        return List.of();
    }

    @Override
    public PageHelper findAllByPage(int pageindex, int pagesize) throws Exception {
        return null;
    }

    @Override
    public PageHelper findPageByRoleIds(int pageindex, int pagesize, int... roleIds) throws Exception {
        return null;
    }
}
